"""
ASGI config for application project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"

from application.websocketConfig import websocket_application
from dvadmin.system.consumers import DvadminWebSocket
from channels.routing import URLRouter, ProtocolTypeRouter
from .routing import application as ws_app

http_application = get_asgi_application()

# async def application(scope,receive,send):
#     if scope['type'] == 'http':
#         await http_application(scope, receive, send)
#     elif scope['type'] == 'websocket':
#         # await websocket_application(scope, receive, send)
#         await ws.connect()
#     else:
#         raise Exception("unsupport potocol type: ,"+ scope['type'])
application = ProtocolTypeRouter(
    {
        "http": http_application,
        "websocket": ws_app
    }
)
